<?php
/**
 * Created by PhpStorm.
 * User: hongy
 * Date: 2016/2/4
 * Time: 17:56
 */

namespace Home\Model;


use Think\Model;

class RedpackModel extends Model
{
    public function addRp($data){
        $this->data($data)->add();
    }

    public function checkRp($openid){
        $where['openid'] = $openid;
        $result = $this->where($where)->find();
        if($result['myname']==NULL) return false;
        if(!$result) return false;
        return $result;
    }

    public function getRp($openid){
        $where['openid'] = $openid;
        $result = $this->where($where)->find();
        if($result) return $result;
        return false;
    }

    public function checkPerson($data){
        $where = array(
            'myname' => $data['yourname'],
            'yourname' => $data['myname'],
            'openid' =>array('NEQ',$data['openid']),
            'status' => array('NEQ',1),
        );
        $result = $this->where($where)->select();
        if($result) return $result;
        return false;
    }

    public function update($openid1,$openid2,$data){
        $where['openid'] = $openid1;
        $this->where($where)->data($data)->save();
        $where1['openid'] = $openid2;
        $this->where($where1)->data($data)->save();
    }

    public function updateOpenid($openid1,$openid2,$data1,$data2){
        $where['openid'] = $openid1;
        $this->where($where)->data($data1)->save();
        $where1['openid'] = $openid2;
        $this->where($where1)->data($data2)->save();
    }

    public function getFriend($openid){
        $where['friend'] = $openid;
        $where['status'] = 1;
        $result = $this->where($where)->find();
        return $result;
    }

    public function deleteJC(){
        $rpmodel = M('Redpack');
        $rpmodel->where(array('openid'=>'odj4wt_AAeyGL5uV57QPClyChNx8'))->delete();
        $rpmodel->where(array('friend'=>'odj4wt_AAeyGL5uV57QPClyChNx8'))->delete();
    }
    public function deleteHY(){
        $rpmodel = M('Redpack');
        $rpmodel->where(array('openid'=>'odj4wt3mMbfSfLqnJ34ROLilJ_q8'))->delete();
        $rpmodel->where(array('friend'=>'odj4wt3mMbfSfLqnJ34ROLilJ_q8'))->delete();
    }

    public function findMe($openid){
        $where['openid'] = $openid;
        $result = $this->where($where)->find();
        return $result;

    }

    public function loadOut(){
        $where['ka'] = 0;
        return $this->where($where)->select();

    }
}